package com.csw.android.localplayer.ui

import android.Manifest
import android.os.Bundle
import android.view.View
import com.csw.android.dev_utils.ex.ActivityEx.openInCommonActivity
import com.csw.android.dev_utils.ui.databinding.DataBindingActivity
import com.csw.android.localplayer.R
import com.csw.android.localplayer.databinding.UiMainBinding
import com.csw.android.localplayer.ui.local.LocalListFragment
import com.csw.android.player.service.PlayService
import com.scwang.smart.refresh.footer.ClassicsFooter
import com.scwang.smart.refresh.header.MaterialHeader
import com.scwang.smart.refresh.layout.SmartRefreshLayout
import com.tbruyelle.rxpermissions3.RxPermissions

class MainActivity : DataBindingActivity<UiMainBinding>() {
    override fun getContentViewID() = R.layout.ui_main

    override fun initView(rootView: View, savedInstanceState: Bundle?) {
        super.initView(rootView, savedInstanceState)
        PlayService.startService(this)
        //设置下拉刷新和上拉加载更多的样式
        SmartRefreshLayout.setDefaultRefreshHeaderCreator { context, _ ->
            return@setDefaultRefreshHeaderCreator MaterialHeader(context)
        }
        SmartRefreshLayout.setDefaultRefreshFooterCreator { context, _ ->
            return@setDefaultRefreshFooterCreator ClassicsFooter(context).setDrawableSize(20f)
        }
    }

    override fun initListener() {
        super.initListener()
        dataBinding?.run {
            localList.setOnClickListener {
                RxPermissions(this@MainActivity)
                    .request(Manifest.permission.READ_EXTERNAL_STORAGE)
                    .subscribe {
                        openInCommonActivity<LocalListFragment>()
                    }
            }
        }

    }

}